package butines.game2.sterring;

import java.util.ArrayList;
import java.util.List;

import butines.common.math.Vector2D;

public class Path {

    private List<Vector2D> waypoints;
    private boolean looped;

    private int current;

    public Path() {
        
    }
    
    public boolean isLooped() {
        return looped;
    }

    public void setLooped(boolean looped) {
        this.looped = looped;
    }

    public Vector2D getCurrentWaypoint() {
        return getWaypoints().get(current);
    }

    public int size() {
        return getWaypoints().size();
    }
    
    // returns true if the end of the list has been reached
    public boolean isFinished() {
        return current >= size() - 1;
    }
    
    public void nextWaypoint() {
        if (current < size() - 1) {
            current++;
        }
        if (current == size() && looped) {
            current = 0;
        }
    }
    
    public void addWayPoint(Vector2D wayPoint) {
        getWaypoints().add(wayPoint);
    }
    
    public List<Vector2D> getWaypoints() {
        if (waypoints == null) {
            waypoints = new ArrayList<>();
        }
        return waypoints;
    }

    public void setWaypoints(List<Vector2D> waypoints) {
        this.waypoints = waypoints;
        current = 0;
    }
  
    public void clear() {
        current = 0;
        getWaypoints().clear();
    }

}
